package Java.BlackHorse.Thread.Thread5;

import static java.lang.Thread.sleep;

public class MyThread implements Runnable {

    int ticket = 1;

    @Override
    public void run() {
        while (true) {
          if(method())break;
        }
    }

    public synchronized boolean method() {
        if (ticket > 100) {
            return true;
        } else {
            try {
                sleep(100);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(Thread.currentThread().getName() + " 正在售卖第 " + ticket + " 张票 ");
            ticket++;
        }
        return false;
    }

}


